class KeywordModel {
	key = 'history'
	maxLength = 15
	getHistory() {
		const words = uni.getStorageSync(this.key)
		if(!words) {
			return []
		}
		return words
	}
	
	addToHistory(keywrod) {
		let words = this.getHistory()
		const has = words.includes(keywrod)
		if(!has) {
			 // 数组末尾 删除 ， keyword 数组第一位
			const length = words.length
			if(length >= this.maxLength) {
				words.pop()
			}
			words.unshift(keywrod)
			uni.setStorageSync(this.key, words)
		}
	}
	
	deleteToHistory() {
		uni.removeStorageSync(this.key)
	}
	
}


export { KeywordModel } 